<?php 
include "includes/session.php";
include "includes/comunes.php";
require_once("includes/paginator.class.php");
$pages = new Paginator;

$sql="select * from (select * from  boletocompra,personas,vehiculo where boletoVendedor=personaId and boletoVehiculo=idAuto) as T1
 ";
//armo el Where de la consutla
$where=" where 1 ";
//if(!isset($_GET['submit']))
//    $where.=" and vendido=0";

 if($_GET['patente']<>"")
     $where.=" and patente='".trim($_GET['patente'])."'";
 
 
 if($_GET['marca']<>"" and $_GET['marca']<>0)
     $where.=" and idMarca=".$_GET['marca'];
if($_GET['modelo']<>"" and $_GET['modelo']<>0)
     $where.=" and idModelo=".$_GET['modelo'];
if($_GET['version']<>"" and $_GET['version']<>0)
     $where.=" and idVersion=".$_GET['version'];
if($_GET['ano']<>"" and $_GET['ano']<>0)
     $where.=" and ano=".$_GET['ano'];
if($_GET['fechad']<>"")
     $where.=" and boletofecha >='".$_GET['fechad']."'";
if($_GET['predesde']<>"")
     $where.=" and boletofecha <='".$_GET['fechah']."'";

if($_GET['vendedor']<>""){
	$ven=explode('-',$_GET['vendedor']);
     $where.=" and boletovendedor =".(int)$ven[0];
}


$where.=" order by boletoId desc "   ;
 


//realizo la consulta paro obtener los totales

$result= cons_sql_up($sql.$where);
//finc consulta

$pages->items_total = mysql_num_rows($result);
$pages->mid_range = 9;
$pages->paginate();
$result=  $result= cons_sql_up($sql.$where.$pages->limit);
//echo $sql.$where.$pages->limit;die();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta HTTP-EQUIV="refresh" CONTENT="300"/>
<title>Sistema de Gestion de Vehiculos</title>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="estilos.css" rel="stylesheet" type="text/css" />

<!--libreria jquery central-->

<script src="jquery-ui/js/jquery-1.9.1.js"></script>
<!--fin libreria central-->

<!--Librerias para el combo-->
<script language="JavaScript" type="text/javascript" src="combos/jquery.chainedSelects.js"></script>
<!--fin libreria-->

<!--librerias ui-->
<link href="jquery-ui/css/ui-lightness/jquery-ui-1.10.2.custom.css" rel="stylesheet"/>
<script src="jquery-ui/js/jquery-ui-1.10.2.custom.js"></script>
<!--fin libreria-->
<!--libreria flexigrid-->
<link rel="stylesheet" type="text/css" href="jquery-ui/css/ui-flexigrid/flexigrid.css">
    <script type="text/javascript" src="jquery-ui/js/flexigrid.js"></script>
<!--fin libreria-->



<script language="JavaScript" type="text/javascript">
$(function()
{

//        funcion que implementa combos
	$('#marca').chainSelect('#modelo','combomarcamodelo.php',
	{
		before:function (target) //before request hide the target combobox and display the loading message
		{
			$("#loading").css("display","block");
			$(target).css("display","none");
		},
		after:function (target) //after request show the target combobox and hide the loading message
		{
			$("#loading").css("display","none");
			$(target).css("display","inline");
		}
	});
        
        $('#modelo').chainSelect('#version','combomodeloversion.php',
	{
		before:function (target) //before request hide the target combobox and display the loading message
		{
			$("#loading").css("display","block");
			$(target).css("display","none");
		},
		after:function (target) //after request show the target combobox and hide the loading message
		{
			$("#loading").css("display","none");
			$(target).css("display","inline");
		}
	});
        
        
           $('#venpro').chainSelect('#venloc','comboprolocalidad.php',
	{
		before:function (target) //before request hide the target combobox and display the loading message
		{
			$("#loading").css("display","block");
			$(target).css("display","none");
		},
		after:function (target) //after request show the target combobox and hide the loading message
		{
			$("#loading").css("display","none");
			$(target).css("display","inline");
		}
	});
        
//        fin funcion

//          funcion datapicker

       $( "#fechad" ).datepicker({
         dateFormat: "yy-mm-dd"

      });
	  
	  $( "#fechah" ).datepicker({
         dateFormat: "yy-mm-dd"

      });
       
//             funcion

//funcion autocomplete
                $( "#patente" ).autocomplete({
			source: "autoPatentes.php"
		});
		
		   $( "#vendedor" ).autocomplete({
			source: "autoVendedor.php"
		});


//fin funcion




  $('#flex1').flexigrid({
      colModel : [
                
		{display: 'Nro.Boleto', name : 'boletoId', width : 60, sortable : true, align: 'center'},
		{display: 'DNI', name : 'dni', width : 60, sortable : true, align: 'left'},
		{display: 'Nombre y Apellido', name : 'nomyape', width : 150, sortable : true, align: 'left'},
		{display: 'Tipo Contrato', name : 'nomyape', width : 80, sortable : true, align: 'left'},
		{display: 'Vehiculo', name : 'nomyape', width : 190, sortable : true, align: 'left'},
		{display: 'fecha', name : 'fecha', width : 60, sortable : true, align: 'left'},
                {display: 'Precio', name : 'acciones', width : 105, sortable : false, align: 'left'}
		],
                width: 450,
                height: 1000
              
  });
<?php for ($i=1;$i<30;$i++):?>
  $('#fila<?php echo $i?>').tooltip({
      track: true
    });
 
<?php endfor?>
<?php for ($i=1;$i<30;$i++):?>
  $('#visualizar<?php echo $i?>').tooltip({
      track: true
    });

<?php endfor?>
 <?php for ($i=1;$i<30;$i++):?>
  $('#editar<?php echo $i?>').tooltip({
      track: true
    });

<?php endfor?>
<?php for ($i=1;$i<30;$i++):?>
  $('#imprimir<?php echo $i?>').tooltip({
      track: true
    });

<?php endfor?>
<?php for ($i=1;$i<30;$i++):?>
  $('#tratar<?php echo $i?>').tooltip({
      track: true
    });

<?php endfor?>
});
</script>



</head>

<body>

<div class="container">
<?php include "includes/head.php"?>
   <div class="content">
       <div class="tituloprincipal">
           <?php include 'includes/submenu.php';?>  
           <img src="img/pedidos.jpg" width="25" height="25" border="0"/> Reporte de Compras
           </div>
       
       <div class="contenedorpedido">
       <form id="boletocompra" name="boletocompra" method="GET" action="ReporteCompras.php">
        <fieldset>
             <legend><b>Seleccione Filtros</b></legend>
             <table>
                 <tr>

                    <td class="textotablamenuform">Nro. Patente</td>
                    <td class="textotablamenuform"><input type="text" name="patente" id="patente" value="" class="campo_form" /></td>

                     <td class="textotablamenuform">Categoria</td>
                     <td class="textotablamenuform">
                          <select name="tipo" id="tipo" class="campo_form" required>

                             <option selected value="0">Seleccionar...</option>
                             <?php
                             $est=  obtener_categorias();

                             while($regest=mysql_fetch_array($est)){
                                 echo "<option value='".utf8_encode($regest['id_categoria'])."'>".utf8_encode($regest['descripcion'])."</option>";
                             }

                             ?>


                            
                         </select>
                     </td>
                     <td class="textotablamenuform">Marca</td>
                     <td class="textotablamenuform">
                          <select name="marca" id="marca" class="campo_form">
                             <option selected value="0">Seleccionar...</option>
                             <?php
                             $ped=  obtener_marcas();

                             while($regPed=mysql_fetch_array($ped)){
                                 echo "<option value='".utf8_encode($regPed['id_marca'])."'>".utf8_encode($regPed['descripcion'])."</option>";
                             }

                             ?>

                         </select>
                                         </td>
                 </tr>
                 <tr>
                     <td class="textotablamenuform">Modelo</td>
                     <td class="textotablamenuform">
                        <select name="modelo" id="modelo" class="campo_form">
                             <option selected value="0">Seleccionar...</option> 
                         </select>
                     </td>
                     <td class="textotablamenuform">Version</td>
                     <td class="textotablamenuform">
                          <select name="version" id="version" class="campo_form">
                            <option selected value="0">Seleccionar...</option>

                         </select>
                     </td>
                     <td class="textotablamenuform">Año</td>
                     <td class="textotablamenuform">
                         <select name="ano" id="ano" class="campo_form" required>
                             <option selected value="0">Seleccionar...</option> 
                         <?php
                             $ped=obtener_anos();

                             while($regPed=mysql_fetch_array($ped)){
                                       echo "<option value='".utf8_encode($regPed['id_ano'])."'>".utf8_encode($regPed['descripcion'])."</option>";
                           

                             }

                             ?>
                           

                         </select>
                     
                     
                     </td>
                 </tr>
                 <tr>
                    <td class="textotablamenuform" >Fecha Operacion Desde</td>
                    <td class="textotablamenuform"><input type="text" name="fechad" id="fechad" value="" class="campo_form" /></td>
                    <td class="textotablamenuform">Fecha Operacion Hasta</td>
                    <td class="textotablamenuform"><input type="text" name="fechah" id="fechah" value="" class="campo_form" /></td></tr>
					
					<tr>
                      <td class="textotablamenuform">Vendedor</td>
                    <td class="textotablamenuform" colspan="3"><input type="text" name="vendedor" id="vendedor" value="" class="campo_form" /></td>
                       
                        </tr>
                 <tr>
<!--                    <td class="textotablamenuform">Sucursal</td>
                    <td class="textotablamenuform" ><select name="sucursal" id="sucursal" class="campo_form">
                      <option selected="selected" value="0">Todos...</option>
                      <?php
//                             $ped=obtener_sucursales();

//                             while($regPed=mysql_fetch_array($ped)){
//                                 
//                                       echo "<option value='".utf8_encode($regPed['sucursalId'])."'>".utf8_encode($regPed['sucursalNombre'])." (".utf8_encode($regPed['sucursalCodigo']).")</option>";
//
//
//                             }

                             ?>
                    </select></td>-->
                 </tr>
                   <tr>
                    <td class="textotablamenuform" style="text-align: right;" colspan="8">
                         <input type="reset" name="enviar" value="Limpiar"  class="boton_form"/>
                         <input name="submit" id="submit" type="submit" value="Realizar Busqueda" class="boton_form"/>
                     </td>
                 </tr>
             </table>
        </fieldset>
       </form>
           <fieldset>
             <legend><b>Resultado de la Busqueda</b></legend>
             
             </br>

             <table id="flex1"style="display:none;width: 80%">

               <tbody>

                <?php
                $i=1;
				$total=0;
                if($pages->items_total >0)
                while($reg=  mysql_fetch_array($result)):?>
                  <tr id="fila<?php echo $i?>">
                     
                     <td width="60"><?php echo $reg['boletoId']?></td>
                     <td width="100"><?php echo $reg['personaDniCuit']?></td>
                     <td width="200"><?php echo $reg['personaNombre']?></td>
					 <td width="100"><?php echo obtener_tipo_boleto_compra($reg['boletoTipo'])?></td>
                     <td width="150"><?php echo obtener_desc_vehiculo($reg['boletoVehiculo'])?></td>
                     <td width="60"><?php echo format_fec($reg['boletofecha'],'/')?></td>
                    
                     <td>$ 
					  <?php echo $reg['boletoMonto']?>
					 </td>
                         
                  </tr>
                 <?php
				 $total+=$reg['boletoMonto'];
                 $i++;
                 endwhile
                
                 ?>
				 <tr >
                     
                     <td width="60"></td>
                     <td width="100"></td>
                     <td width="200"></td>
					 <td width="100"></td>
                     <td width="150">Total</td>
                     <td width="60"><?php echo $i-1?></td>
                    
                     <td>$ 
					  <?php echo $total?>
					 </td>
                         
                  </tr>

                   <tr>
                       <td colspan="8"><?php echo $pages->display_jump_menu();echo $pages->display_items_per_page();echo $pages->display_pages() ?></td>
                   </tr>
                </tbody>

             </table>
             

        </fieldset>
           
       </div>
 
       <div class="clear"></div>
   <br>
   </div>
  <?php include "includes/pie.php"?>
  
</div>
</body>
</html>
